/*
 This file 'main' is part of Firebird Integrated Solution 1.0

 Copyright (c) 2015 Lincong

 Contact:  
 Email: lincong1987@gmail.com

 QQ: 159257119

 See Usage at http://www.jplatformx.com/firebird

 Create date: 2015-04-07 11:04
 */

define(function (require, exports, module) {

	var top_menu = {};

	$.ajax({
		url: firebird.data.get("top_menu.url"),
		data: {},
		success: function (json) {
			if (json.success === true && json.data && json.data.length > 0) {
				renderTopMenu(json);
			}
		}
	});

	var renderTopMenu = function (json) {
		


		require.async(["./top_menu.tmpl", "../../css/main/top_menu.css"], function (top_menu_render) {
			 
			var $menu = $(".ui-layout-west-header");


			$menu.before(top_menu_render({
				list: json.data
			}));


			var $top_menu_content_link = $(".top-menu-content a");

			$top_menu_content_link.on("click", function (e) {
				var $target = $(e.target);
				var me = $target.is("a") ? $target : $target.closest("a");

				firebird.data.get("system.tab").create(me.data("id"));

				e.preventDefault();
				

			})

		});


	};


	module.exports = top_menu;
});